//
//  XDViewController.m
//  XinDong
//
//  Created by hy005 on 12-11-8.
//  Copyright (c) 2012年 HengYongKeJi. All rights reserved.
//

#import "MAViewController.h"

@interface MAViewController ()

@end

@implementation MAViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)back
{
    [self.navigationController popViewControllerAnimated:TRUE];
}

- (void)addBackBtn
{

    UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0.f, 0.f, 49.f, 30.f)];
    [backBtn setBackgroundImage:[UIImage imageNamed:@"reback_btn.png"] forState:UIControlStateNormal];
    [backBtn setBackgroundImage:[UIImage imageNamed:@"rebackdown_btn.png"] forState:UIControlStateHighlighted];
    [backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(7.f, 4.f, 40.f, 20.f)];
    title.text = @"返回";
    title.textAlignment = NSTextAlignmentCenter;
    title.backgroundColor = [UIColor clearColor];
    title.textColor = [UIColor whiteColor];
    title.font = SmallFont12;
    [backBtn addSubview:title];
    
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
}

//加入提示框
- (void)addNotice:(NSString*)notice {
    UILabel *noticeView = [[UILabel alloc] initWithFrame:CGRectMake(30.f, 50.f, 5.f, 30.f)];
    noticeView.text = notice;
    noticeView.textColor = [UIColor whiteColor];
	noticeView.textAlignment = UITextAlignmentCenter;
	noticeView.font = [UIFont boldSystemFontOfSize:12.f];
	[noticeView setBackgroundColor:[UIColor blackColor]];
	[noticeView sizeToFit];
	noticeView.frame = CGRectMake((320.f - noticeView.frame.size.width - 20.f)/2, 100.f, noticeView.frame.size.width + 20.f, 30.f);
	noticeView.layer.cornerRadius = 6.f;
	noticeView.layer.masksToBounds = true;
	noticeView.alpha = 0.8f;
    
    [self.view addSubview:noticeView];
    if(noticeView && [self respondsToSelector:@selector(dismissNotice:)]){
        [self performSelector:@selector(dismissNotice:) withObject:noticeView afterDelay:1.0f];
    }
}

- (void)dismissNotice:(UILabel*)noticeView {
    noticeView.alpha = 0.8f;
	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationDuration:8.f];
	noticeView.alpha = 0.0f;
	[UIView commitAnimations];
    if(noticeView && [noticeView respondsToSelector:@selector(removeFromSuperview)]){
        [noticeView performSelector:@selector(removeFromSuperview)];
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"topbar_redback.png"] forBarMetrics:UIBarMetricsDefault];
    }

    NSArray *viewControllers = self.navigationController.viewControllers;
    if ([viewControllers indexOfObject:self] > 0) {
        [self addBackBtn];
    }
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
}

//-(void)didPressBKButton
//{
//    return;
//}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
